package cn.wit.testalgorithms;

/**
 * 35.搜索插入位置
 * 
 * @author 16604
 *
 */
public class DemoSearchInsertPosition {
	public static void main(String[] args) {
		int[] a = { 1, 3, 5, 6 };
		int val = 7;
		System.out.println(searchInsert(a, val));
	}

	public static int searchInsert(int[] nums, int target) {
		int i;

		if (nums.length == 1) {
			return nums[0] >= target ? 0 : 1;
		}

		for (i = 0; i < nums.length; i++) {
			if (nums[i] >= target) {
				return i;
			}
		}

		return i + 1;

	}

}
